package pile.pay.controller;


import com.alipay.api.AlipayApiException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pile.pay.config.huifuPayConfig.TradePayment;
import pile.pay.config.wxConfig.WxRefundEntity;
import pile.pay.entity.ResponseResult;
import pile.pay.service.IHuiFuPayService;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SignatureException;

@RestController
@RequestMapping("/huifupay")
@Api(tags = {"汇付支付"})
public class HuiFuPayController {

    @Autowired
    private IHuiFuPayService huiFuPayService;

    /**
     * 统一下单-统一接口
     */
    @PostMapping("/transactions")
    @ApiOperation(value = "统一下单", notes = "前段菜单:<br>" +
            "注意事项:<br>" +
            "处理逻辑:")
    public ResponseResult transactions(@Validated @RequestBody TradePayment tradePayment) {
        return huiFuPayService.transactions(tradePayment);
    }


    @PostMapping("/payNotify")
    @ApiOperation(value = "汇付支付回调", notes = "前段菜单:<br>" +
            "注意事项:<br>" +
            "处理逻辑:")
    public String payNotify(HttpServletRequest request, HttpServletResponse response) throws AlipayApiException {
        return huiFuPayService.payNotify(request,response);
    }


    /**
     * 汇付退款回调
     * @param request
     * @param response
     * @return
     * @throws AlipayApiException
     */
    @PostMapping("/refundsNotify")
    @ApiOperation(value = "汇付退款回调", notes = "前段菜单:<br>" +
            "注意事项:<br>" +
            "处理逻辑:")
    public String refundsNotify(HttpServletRequest request, HttpServletResponse response) {
        return huiFuPayService.refundsNotify(request,response);
    }



    /**
     * 汇付申请退款
     */
    @PostMapping("/refunds")
    @ApiOperation(value = "汇付申请退款", notes = "前段菜单:<br>" +
            "注意事项:<br>" +
            "处理逻辑:")
    public ResponseResult refunds() {
        return huiFuPayService.refunds();
    }




}
